package com.cxy.hmall.db.service;

import com.cxy.hmall.db.dao.HGoodsAttributeMapper;
import com.cxy.hmall.db.domain.HGoodsAttribute;
import com.cxy.hmall.db.domain.HGoodsAttributeExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class HGoodsAttributeService {
	@Resource
	private HGoodsAttributeMapper goodsAttributeMapper;

	public List<HGoodsAttribute> queryByGid(Integer goodsId) {
		HGoodsAttributeExample example = new HGoodsAttributeExample();
		example.or().andGoodsIdEqualTo(goodsId).andDeletedEqualTo(false);
		return goodsAttributeMapper.selectByExample(example);
	}

	public void add(HGoodsAttribute goodsAttribute) {
		goodsAttribute.setAddTime(LocalDateTime.now());
		goodsAttribute.setUpdateTime(LocalDateTime.now());
		goodsAttributeMapper.insertSelective(goodsAttribute);
	}

	public HGoodsAttribute findById(Integer id) {
		return goodsAttributeMapper.selectByPrimaryKey(id);
	}

	public void deleteByGid(Integer gid) {
		HGoodsAttributeExample example = new HGoodsAttributeExample();
		example.or().andGoodsIdEqualTo(gid);
		goodsAttributeMapper.logicalDeleteByExample(example);
	}
}
